package org.ko.core.logic.auth.impl;


import java.util.List;

import org.ko.core.dao.auth.MenuDao;
import org.ko.core.dao.support.Updater;
import org.ko.core.domain.auth.Menu;
import org.ko.core.logic.auth.MenuSvc;
import org.ko.core.websupport.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 系统菜单管理Svc接口实现
 * @author BQC
 * @version 2014-09-14 15:40:06
 */
@Service
@Transactional
public class MenuSvcImpl implements MenuSvc {

	@Autowired
	private MenuDao dao;

	@Override
	public Menu addDo(Menu bean) {
		
		
		if(1==bean.getType()){
			bean.setIcon("icon-action");
		}
		dao.save(bean);

		return bean;
	}

	/**
	 * 批量删除指定id实例
	 */
	public void delete(Long[] ids) {
		dao.delete(ids);
	}

	public Menu editDo(Menu bean) {
		
		Updater<Menu> updater = new Updater<Menu>(bean);
		updater.exclude("parent");
		Menu ret = dao.updateByUpdater(updater);
		return ret;
	}

	@Override
	public Page findPage(Page p,String searchText) {
		return dao.findPage(p.getPageNo(), p.getPageSize(),searchText);
	}
	

	@Override
	public List findTree(String searchText) {
		return dao.findTree(searchText);
	}
	
	public List findAuthMenus() {
		return dao.findAuthMenus();
	}

	public boolean changeParent(Long id, Long pid) {
		int re = dao.changeParent(id,pid);
		
		return re>0;
	}

	@Override
	public Menu get(Long id) {
		return dao.get(id);
	}

}
